from text import *
from playpage import *
from speedpage import *
# 开始页面
def startPage(screen) :
    Author = TEXT("author : blankspace", AuthorColor, AuthorSize)
    # 背景音乐
    Channel1.play(startPageBGM)
    # 页面各种字体
    Title = TEXT("Greedy Snake", titleColor, titleSize)
    Play = TEXT("play", startPageTextColor, startPageTextSize)
    Speed = TEXT("speed", startPageTextColor, startPageTextSize)
    Score = TEXT("score", startPageTextColor, startPageTextSize)
    Exit = TEXT("exit", startPageTextColor, startPageTextSize)
    Tip = TEXT("Press the w/s or UP/DOWN key to move the cursor for selection and press ENTER key to choose", startPageTextColor, tipSize)
    # 页面字体打印
    def printText() :
        Title.printText(titlePosition, screen)
        Author.printText(AuthorPosition, screen)
        Tip.printText(tipPosition, screen)
        Play.printText([280, 300], screen)
        Speed.printText([280, 400], screen)
        Score.printText([280, 500], screen)
        Exit.printText([280, 600], screen)
        pygame.display.update()
    # 选项标识
    def drawCircle(k) :
        circlePosition = [[250, 330], [250, 430], [250, 530], [250, 630]]
        pygame.draw.circle(screen, circleColor, circlePosition[k], circleRadius)
        pygame.display.update()
    def clearCircle(k) :
        circlePosition = [[250, 330], [250, 430], [250, 530], [250, 630]]
        pygame.draw.circle(screen, backgroundColor, circlePosition[k], circleRadius)
        pygame.display.update()
    # 页面重置
    def restart() :
        screen.fill(backgroundColor)
        printText()
        drawCircle(startCirclePos)
        pygame.display.update()
    
    startCirclePos = 0
    restart()

    flag = False
    while True :
        for event in pygame.event.get() : # 事件处理
            # 退出
            if event.type == pygame.QUIT :
                return
            if event.type == KEYDOWN :
                if event.key == K_UP or event.key == K_w :
                    if startCirclePos > 0 :
                        Channel4.play(KeyBGM)
                        clearCircle(startCirclePos)
                        startCirclePos -= 1
                        drawCircle(startCirclePos)
                if event.key == K_DOWN or event.key == K_s :
                    if startCirclePos < 3 :
                        Channel4.play(KeyBGM)
                        clearCircle(startCirclePos)
                        startCirclePos += 1
                        drawCircle(startCirclePos)
                if event.key == K_RETURN :
                    Channel4.play(KeyBGM)
                    if startCirclePos == 0 :
                        Channel1.stop()
                        playPage(screen)
                        Channel1.play(startPageBGM)
                        flag = True
                    elif startCirclePos == 1 :
                        speedPage(screen)
                        flag = True
                    elif startCirclePos == 2 :
                        scorePage(screen)
                        flag = True
                    else :
                        return
        if flag :
            restart()
            flag = False